<template>
    <div>
<table>
    <tbody>
        <tr>
            <td>房号</td>
            <td>
<input type="text" name="" v-model="date.name" id="">
            </td>
        </tr>
        <tr>
            <td>图片</td>
            <td>
<input type="file" name="" @change="upload" id="">
<img :src="'https://localhost:7093/'+date.img" width="200px" height="100px">
            </td>
        </tr>
        <tr>
            <td colspan="2">
<input type="button" value="保存" @click="add">
            </td>
          
        </tr>
    </tbody>
</table>
    </div>
</template>

<script setup lang="ts">
import { ref } from 'vue';
import axios from 'axios';
import { useRouter } from 'vue-router';

const router=useRouter()
const upload=(a:any)=>{
var f=a.target.files[0]
var fd=new FormData()
fd.append("file",f)

axios.post('https://localhost:7093/api/Upload',fd).then(res=>{
    date.value.img=res.data
})
}
const add=()=>{


axios.post('https://localhost:7093/api/Emp/Add',date.value).then(res=>{
    if(res.data>0){
        alert('成功')
        router.push({path:"/show"})
    }else{
        alert('失败')
    }
})
}
const date=ref({
    "id": 0,
  "name": "108",
  "img": "1",
  "state": true
})
</script>

<style scoped>

</style>